package com.p2p.base.web.freemarker;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import com.p2p.base.util.BasePropertyConfigurer;
import com.p2p.base.util.LoginUtil;

/**
 * @author ruiqi
 *
 */
public class BaseFreeMarkerView extends FreeMarkerView {

	@Override
	protected void exposeHelpers(Map<String, Object> model,
			HttpServletRequest request) throws Exception {

		String contextPath = request.getContextPath();
		model.put("base", contextPath);
		String fullPath = request.getScheme() + "://" + request.getServerName()
				+ contextPath;
		model.put("fullPath", fullPath);

		model.put("static",
				BasePropertyConfigurer.getContextProperty("p2p.static"));
		model.put("p2p_domain_name",
				BasePropertyConfigurer.getContextProperty("p2p.domain"));
		model.put("userDomain",
				BasePropertyConfigurer.getContextProperty("p2p.userDomain"));
		model.put("fundsDomain",
				BasePropertyConfigurer.getContextProperty("p2p.fundsDomain"));
		model.put("cmsDomain",
				BasePropertyConfigurer.getContextProperty("p2p.cmsDomain"));
		model.put("loginDomain",
				BasePropertyConfigurer.getContextProperty("p2p.loginDomain"));
		model.put("backendDomain",
				BasePropertyConfigurer.getContextProperty("p2p.backendDomain"));
		model.put("login_url",
				BasePropertyConfigurer.getContextProperty("p2p.login_url"));
		model.put("index",
				BasePropertyConfigurer.getContextProperty("p2p.index"));
		
		/*Object p2p_style = BasePropertyConfigurer.getContextProperty("p2p.style");
		if(p2p_style!=null){
			String style = (String)p2p_style;
			if(StringUtils.equals(style, "css")){
				style="";
			}
			else{
				style="/"+style;
			}
			model.put("style",style);
		}*/
		model.put("style",
				BasePropertyConfigurer.getContextProperty("p2p.style"));

		model.put("company_name",
				BasePropertyConfigurer.getContextProperty("p2p.company_name"));
		Object userObject = LoginUtil.getCurrentUser();
		
		model.put("currentUser", userObject);
		super.exposeHelpers(model, request);
	}
	

}
